package com.apesource.mallproject.controller;

import com.apesource.mallproject.pojo.Seller;
import com.apesource.mallproject.service.ISellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(allowCredentials = "true", maxAge = 3600)
public class SellerController {
    @Autowired
    private ISellerService sellerService;

    @RequestMapping("/findAll")
    public List<Seller> findAll() {
        return sellerService.findAll();
    }


    @RequestMapping(value = "/showLike")
    public List<Seller> showLike(@RequestParam("name") String name, @RequestParam("nickName") String nickName, @RequestParam("status") String status) {

       /* RequestBody接受的是jason，得到的是键值对=,,RequestParam得到的是地址栏里的数据
       String ss = status.substring(status.indexOf("=") + 1);
        String sname = name.substring(name.indexOf("=") + 1);
        String snick = nickName.substring(nickName.indexOf("=") + 1);*/
        Integer s = Integer.parseInt(status);
        return sellerService.showLike(name, nickName, s);
    }

    @RequestMapping("/showStatus")
    public List<Seller> showStatus() {
        return sellerService.showStatus();
    }

    @RequestMapping("/updateStatus/{id}")
    public void updateStatus(@PathVariable String id) {
        sellerService.updateStatus(Integer.parseInt(id));
        System.out.println(id);
    }

    @RequestMapping("/updateNoStatus/{id}")
    public void updateNoStatus(@PathVariable String id) {
        Integer sellerId = Integer.parseInt(id);
        sellerService.updateNoStatus(sellerId);
        System.out.println(id);
    }

    @RequestMapping("/delSeller/{id}")
    public void delSeller(@PathVariable String id) {
        Integer sellerId = Integer.parseInt(id);
        sellerService.delSeller(sellerId);
    }

    @RequestMapping("/updateCloseStatus/{id}")
    public void updateCloseStatus(@PathVariable String id) {
        Integer sellerId = Integer.parseInt(id);
        sellerService.updateCloseStatus(sellerId);
    }
}
